package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.pojo.GoodsType;
import com.gxa.zhonglong.pojo.GoodsWeight;
import com.gxa.zhonglong.service.GoodsTypeService;
import com.gxa.zhonglong.service.GoodsWeightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author NITRO
 */

@Api
@CrossOrigin
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @ApiOperation(value = "添加商品种类")
    @PostMapping("/addGoodsType")
    public Map addGoodsType( GoodsType goodsType) throws BusinessException {
        JsonResult jsonResult=new JsonResult();
        goodsTypeService.add(goodsType);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


    @PostMapping("/deleteGoodsType")
    @ApiOperation("删除商品种类")
    public Map<String,Object> deleteGoodsType(@RequestBody Map<String,List<Long>> ids) throws BusinessException {
        goodsTypeService.delete(ids.get("ids"));
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "修改商品种类")
    @PostMapping("/updateGoodsType")
    public Map updateType( GoodsType goodsType) throws BusinessException {
        JsonResult jsonResult = new JsonResult();
        goodsTypeService.update(goodsType);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "查询商品种类")
    @PostMapping("/getGoodsTypeList")

    public Map getGoodsTypeList(){


        List<GoodsType> list = goodsTypeService.getList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(list);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
}
